import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

class ListOfNumbers {
    private int[] list = new int[100];

    ListOfNumbers() {
        //在列表数组中存储整数值
        for (int i = 0; i < 100; i++) {
            list[i] = i;
        }
    }
    public void writeList() {
        PrintWriter out = null;

        try {
            System.out.println("进入try语句");

            //创建一个新文件OutputFile.txt
            out = new PrintWriter(new FileWriter("406.txt"));

            //将值从列表数组写入新创建的文件
            for (int i = 0; i < 10; i++) {
                out.println("写入值: " + i + " = " + list[i]);
            }
        } catch (IndexOutOfBoundsException e1) {
            System.out.println("IndexOutOfBoundsException => " + e1.getMessage());
        } catch (IOException e2) {
            System.out.println("IOException => " + e2.getMessage());
        } finally {
            //检查PrintWriter是否被打开
            if (out != null) {
                System.out.println("关闭PrintWriter");
                out.close();
            } else {
                System.out.println("PrintWriter无法打开");
            }
        }

    }

}


public class main {

    public static void main(String[] args) {
        ListOfNumbers list = new ListOfNumbers();
        list.writeList();
    }
}
